
package com.bstek.urule.model.rete;

import com.bstek.urule.model.rule.lhs.NamedCriteria;
import com.bstek.urule.runtime.rete.Activity;
import com.bstek.urule.runtime.rete.CriteriaActivity;
import com.bstek.urule.runtime.rete.NamedCriteriaActivity;

import java.util.Map;

/**
 * @author Jacky.gao
 * @since 2016年8月15日
 */
public class NamedCriteriaNode extends BaseReteNode implements ConditionNode {
    private String criteriaInfo;
    private NamedCriteria criteria;
    private NodeType nodeType = NodeType.namedCriteria;
    private boolean debug;

    public NamedCriteriaNode() {
        super(0);
    }

    public NamedCriteriaNode(NamedCriteria criteria, int id, boolean debug) {
        super(id);
        this.criteria = criteria;
        setCriteriaInfo(criteria.getId());
        this.debug = debug;
    }

    @Override
    public NodeType getNodeType() {
        return nodeType;
    }

    @Override
    public NamedCriteria getCriteria() {
        return criteria;
    }

    public void setCriteria(NamedCriteria criteria) {
        this.criteria = criteria;
    }

    @Override
    public String getCriteriaInfo() {
        return criteriaInfo;
    }

    public void setCriteriaInfo(String criteriaInfo) {
        this.criteriaInfo = criteriaInfo;
    }

    @Override
    public Activity newActivity(Map<Object, Object> context) {
        if (context.containsKey(this)) {
            return (CriteriaActivity) context.get(this);
        }
        NamedCriteriaActivity activity = new NamedCriteriaActivity(criteria, debug);
        for (Line line : lines) {
            activity.addPath(line.newPath(context));
        }
        context.put(this, activity);
        return activity;
    }
}
